<?php

namespace App\Http\Controllers\home;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;
class IntegralController extends Controller
{
    public function getIndex(){
    	// 通过session查询用户id
    	$username = session('username');
    	$id = DB::table('users') -> where('user_email',$username) -> orwhere('user_phone',$username) -> first()['id'];
    	// 查询用户剩余积分
    	$score = DB::table('users')
	            ->join('user_details', 'users.id', '=', 'user_details.user_id')
	            ->select('user_details.user_integral')
	            ->where('users.id',$id)
	            ->first()['user_integral'];
	    // 查询积分兑换商品
    	$data = DB::table('user_integral') -> get();
        return view('home.integral.index',['data'=>$data,'score'=>$score,'username'=>$username]);

    }
}
